Skip to content

Fiet-440 - #20

Merged
victorshevtsov merged 7 commits into
masterfrom
FIET-440
Dec 23, 2025
Merged

Fiet-440#20
victorshevtsov merged 7 commits into
masterfrom
FIET-440

Conversation

@xlassix

@xlassix xlassix commented Nov 20, 2025

Copy link
Copy Markdown
Collaborator

This PR is dependent on the approval and deployment of ccxt 0.0.13

  • FetchAccountId added to cex-broker

Summary by CodeRabbit

  • New Features

    • Add support for fetching account identifiers from multiple exchanges (Bybit, MEXC, Binance-compatible), returning normalized accountId and uid.
  • Chores

    • Bump package version to 0.1.19 and update CCXT dependency for improved exchange compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

Comment thread src/server.ts
@coderabbitai

coderabbitai Bot commented Nov 26, 2025

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Added a new FetchAccountId action to obtain unique CEX account identifiers. Protobuf enum, server handler, constants, and a dev client test were updated; package version and a CCXT dependency were bumped.

Changes

Cohort / File(s) Summary
Protocol & Constants
src/proto/node.proto, src/helpers/constants.ts
Added FetchAccountId=11 to Action enum. Appended "fetchAccountId" to CCXT_METHODS_WITH_VERITY.
Server Implementation
src/server.ts
Implemented Action.FetchAccountId branch: attempts broker-specific API calls (Bybit, MEXC, Binance) to extract accountId/uid, returns normalized JSON payload plus verityProof; includes error handling and logging. Minor formatting tweak in deposit address resolution.
Client Dev/Test
src/client.dev.ts
Replaced a dev ExecuteAction call to use cex "mexc" with FetchAccountId; removed symbol/payload for that call, adjusted log output, and left prior balance test commented out.
Package Manifest
package.json
Bumped package version 0.1.180.1.19. Updated @usherlabs/ccxt ^0.0.12^0.0.13.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant CEX_API as "CEX API (Bybit/MEXC/Binance)"

    Client->>Server: ExecuteAction(FetchAccountId, cex, apiKey)
    activate Server

    alt Bybit path
        Server->>CEX_API: privateGetV5UserQueryApi()
        CEX_API-->>Server: { id, userID, ... }
        Server->>Server: accountId = id, uid = userID
    else MEXC path
        Server->>CEX_API: spotPrivateGetUid()
        CEX_API-->>Server: { uid, ... }
        Server->>Server: accountId = uid, uid = uid
    else Binance path
        Server->>CEX_API: privateGetAccount()
        CEX_API-->>Server: { uid, ... }
        Server->>Server: accountId = uid, uid = uid
    else Unsupported
        Server-->>Client: INTERNAL error (unsupported broker)
    end

    Server->>Server: generate verityProof
    Server-->>Client: { accountId, uid, verityProof }
    deactivate Server
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review protobuf change for numeric tag addition (FetchAccountId=11) and verify consumers handle new enum value.
  • Validate broker-specific extraction logic in src/server.ts (correct endpoints/field names and permission assumptions).
  • Confirm verityProof generation/format and JSON stringification of identifiers match verification consumers.
  • Check src/client.dev.ts test change for intended behavior and ensure commented legacy test is harmless.

Poem

🐰 I hopped in code to find a name,
FetchAccountId joins the game.
Bybit, MEXC, Binance too—
One ID proves each key is true.
Hooray—no duplicate fluff to tame! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Fiet-440' is an issue reference but lacks descriptive content about the actual changes made. Use a descriptive title like 'Add FetchAccountId action to detect duplicate CEX accounts' to clearly communicate the main change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements FetchAccountId fetching with support for Bybit, MEXC, and Binance per FIET-440 requirements [FIET-440].
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the FetchAccountId feature; package version bump and CCXT dependency update are necessary supporting changes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (4)
src/helpers/constants.ts (1)

3-4: Pre-existing issue: duplicate "fetchDepositAddress" entry.

Lines 3-4 contain duplicate "fetchDepositAddress" entries. While this is a pre-existing issue (not introduced by this PR), consider removing the duplicate in a follow-up cleanup.

src/server.ts (3)

221-221: Address the type safety concern flagged in past reviews.

Using (broker as any) completely bypasses TypeScript's type checking. While necessary for dynamic method access, consider:

  1. Documenting why this is needed (these are exchange-specific private methods not in the CCXT type definitions)
  2. Creating a typed interface for the expected methods if this pattern grows
  3. Adding runtime validation (already suggested above)

Based on past review comments, this approach (checking method existence) was agreed upon, but the lack of response validation remains a concern.


257-265: Improve error logging to aid debugging.

The error message doesn't indicate which method was attempted or what the actual error was. Include more context in the log and error response.

Apply this diff:

  } catch (error) {
-   log.error(`Error fetching account ID ${cex}:`, error);
+   log.error(`Error fetching account ID from ${cex}:`, { error, cex, methods: {
+     bybit: typeof temp_broker?.privateGetV5UserQueryApi === "function",
+     mexc: typeof temp_broker?.spotPrivateGetUid === "function",  
+     binance: typeof temp_broker?.privateGetAccount === "function"
+   }});
    callback(
      {
        code: grpc.status.INTERNAL,
-       message: `Error fetching account ID from ${cex}`,
+       message: `Error fetching account ID from ${cex}: ${error instanceof Error ? error.message : 'Unknown error'}`,
      },

216-268: Consider rate limiting and caching for account ID fetches.

Per the PR objectives, account ID proofs should be generated once (not cron-based) and stored. However, the current implementation doesn't include:

  • Rate limiting to prevent abuse
  • Caching to avoid redundant API calls for the same credentials
  • Verification of required API permissions

While these may be handled at a higher level, consider adding protective measures to prevent hitting exchange rate limits.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4423f70 and b0f4813.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • package.json (2 hunks)
  • src/client.dev.ts (1 hunks)
  • src/helpers/constants.ts (1 hunks)
  • src/proto/node.proto (1 hunks)
  • src/server.ts (3 hunks)
🔇 Additional comments (5)
package.json (1)

3-3: LGTM: Version bump is appropriate.

The minor version increment correctly reflects the addition of a new feature (FetchAccountId action).

src/helpers/constants.ts (1)

12-12: LGTM: fetchAccountId correctly added to verity methods.

The addition of "fetchAccountId" to CCXT_METHODS_WITH_VERITY is correct and aligns with the new FetchAccountId action that requires TLS proof verification.

src/client.dev.ts (1)

71-85: LGTM: Test correctly updated for FetchAccountId.

The test appropriately:

  • Removes symbol and payload fields (not needed for account ID fetch)
  • Uses MEXC exchange for testing
  • Applies optional chaining for safe property access

The changes correctly validate the new FetchAccountId functionality.

src/server.ts (2)

428-439: LGTM: Formatting adjustment without behavior change.

The refactored ternary operation improves readability while maintaining the same logic: use fetchDepositAddress if available, otherwise fall back to fetchDepositAddressesByNetwork.


224-228: The code is correct — no issue exists here.

The Bybit API documentation confirms that the /v5/user/query-api endpoint returns userID (camelCase) as an integer field, exactly as the code uses it on line 227. This is not an inconsistency with MEXC or Binance—each exchange API uses its own field names (userID for Bybit, uid for MEXC). The code correctly handles each API's distinct response structure.

Comment thread package.json
"@grpc/grpc-js": "^1.13.4",
"@grpc/proto-loader": "^0.7.15",
"@usherlabs/ccxt": "^0.0.12",
"@usherlabs/ccxt": "^0.0.13",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Script executed:

npm view @usherlabs/ccxt@0.0.13 version 2>/dev/null || echo "Version 0.0.13 not found"

Repository: usherlabs/cex-broker


<shell_result>
Repository: usherlabs/cex-broker
Exit code: 0

stdout:

Version 0.0.13 not found

</shell_result>


@usherlabs/ccxt@0.0.13 does not exist on npm registry.

The version specified in this PR is not available for download. As this change depends on the deployment of ccxt 0.0.13 (per the PR description), the package must be published to npm before this PR can be merged. Verify with the maintainers that the version has been released or coordinate the publication.

🤖 Prompt for AI Agents
In package.json around line 53, the dependency entry "@usherlabs/ccxt":
"^0.0.13" refers to a package version that does not exist on the npm registry;
update this to a valid published version or revert the version change. Ask the
maintainers to publish v0.0.13 before merging or change the dependency to an
existing released version (or a temporary fork/path) and update package.json
accordingly, then run npm install/npm ci and verify lockfile updates and CI
passes.

Comment thread src/proto/node.proto Outdated
Comment thread src/server.ts Outdated
Comment thread src/server.ts Outdated
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​usherlabs/​ccxt@​0.0.12 ⏵ 0.0.1383 +110010094 -1100

View full report

@victorshevtsov
victorshevtsov merged commit 23887d7 into master Dec 23, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants